package com.work.straighttalk.app;

import android.app.Application;
import android.content.Context;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.hyphenate.chat.EMClient;
import com.work.straighttalk.StraightHelp;
import com.hyphenate.chat.EMOptions;

import cn.bmob.v3.Bmob;
import cn.smssdk.SMSSDK;

/**
 * Created by dllo on 16/3/2.
 */
public class StraightTalk extends Application {


    private static final String TAG = "TAGGG";


    public static Context applicationContext;
    private static StraightTalk INSTANCE;

    public static StraightTalk INSTANCE() {
        return INSTANCE;
    }

    private void setInstance(StraightTalk app) {
        setStrightTalk(app);
    }

    private static void setStrightTalk(StraightTalk s) {
        StraightTalk.INSTANCE = s;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        applicationContext = this;
        INSTANCE = this;
        setInstance(this);
        //初始化Bmob
        Bmob.initialize(this, "c0bd32ea98e1e7752269e3e6bfdee215");

        //初始化Fresco
        Fresco.initialize(this);

//        //初始化mob
        SMSSDK.initSDK(this, "ffba1548c04e", "2c72883a953878607cb77433025d8de0");


        //初始化环信
        EMOptions options = new EMOptions();
// 默认添加好友时，是不需要验证的，改成需要验证
        options.setAcceptInvitationAlways(false);
        //默认加载一条消息 节省加载时间
        options.setNumberOfMessagesLoaded(1);
        //已读确认
        options.setRequireAck(true);
        //送达回执
        options.setRequireDeliveryAck(true);
        //服务端信息送达确认
        options.setRequireServerAck(true);
        //
//初始化
        EMClient.getInstance().init(applicationContext, options);
//在做打包混淆时，关闭debug模式，避免消耗不必要的资源
        EMClient.getInstance().setDebugMode(true);

        StraightHelp.getInstance().init(applicationContext);


//        IntentFilter callFilter = new IntentFilter(EMClient.getInstance().callManager().getIncomingCallBroadcastAction());
//        registerReceiver(new CallReceive(), callFilter);

    }

    public static Context getContext() {
        return applicationContext;
    }

    ;

//    private class CallReceive extends BroadcastReceiver {
//
//        @Override
//        public void onReceive(Context context, Intent intent) {
//
//            //拨打方username
//            String from = intent.getStringExtra("from");
//            Log.d("CallReceive", from);
//            //call type
//            String type = intent.getStringExtra("type");
//            if ("video".equals(type)) { //视频通话
////            context.startActivity(new Intent(context, VideoCallActivity.class).
////                    putExtra("username", from).putExtra("isComingCall", true).
////                    addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
//            } else { //音频通话
//                Log.d("CallReceive", "dnisjndig");
//                context.startActivity(new Intent(context, VoiceCallActivity.class).
//                        putExtra("username", from).putExtra("isComingCall", true));
////                        addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
//            }
//            EMLog.d("CallReceiver", "app received a incoming call");
//        }
//    }
}
